package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {
	path := "./04_file_readLine.txt"
	readFileLine(path)
}

func readFileLine(path string) {
	file, err := os.Open(path)
	if err != nil {
		fmt.Println(" readFile-err : ", err)
	}

	defer file.Close()

	/**
		1 新建缓存区,把内容整体放入缓存区中
		2 遍历循环，遇到'\n'结束读取,但要注意'\n'不要读取进来
	**/
	stash := bufio.NewReader(file)
	for {
		buffer, linErr := stash.ReadBytes('\n')
		if linErr != nil {
			if linErr == io.EOF {
				break
			}
			fmt.Println("err = ", err)
		}
		fmt.Printf(" \n buffer-line = #%s# \n ", string(buffer))
	}

	// fmt.Println(" buffer = \n ", string(buffer[:fn]))

}
